package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Keyword;
import com.cskaoyan.bean.ListData;
import com.cskaoyan.service.KeywordService;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Key;

@RequestMapping("admin/keyword")
@RestController
public class KeywordController {
    @Autowired
    KeywordService keywordService;

    @GetMapping("list")
    public BaseRespVo list(Integer page, Integer limit, String sort, String order, String keyword, String url) {
        ListData listData = keywordService.list(page, limit, sort, order, keyword, url);
        return BaseRespVo.ok(listData);
    }

    // 添加
    @PostMapping("create")
    public BaseRespVo create(@RequestBody Keyword keyword) {
        Keyword keywordVo = keywordService.create(keyword);
        return BaseRespVo.ok(keywordVo);
    }

    // 编辑
    @PostMapping("update")
    public BaseRespVo update(@RequestBody Keyword keyword) {

        keywordService.update(keyword);

        return BaseRespVo.ok(keyword);

    }

    // 删除
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Keyword keyword) {
        int delete = keywordService.delete(keyword);
        if (delete != 1) {
            return BaseRespVo.fail("删除失败");
        }
        return BaseRespVo.ok();
    }

}
